﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Services;
using System.Configuration;

namespace brockredge
{
    public partial class WebForm1 : System.Web.UI.Page
    {
       
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
            //SqlDataReader ddDR = null;
            //SqlConnection ddSqlConnection = new SqlConnection("Data Source=NSS;Initial Catalog=brokredge;Integrated Security=True;");
            //SqlCommand ddSqlCommand = new SqlCommand("SELECT * FROM state", ddSqlConnection);
            //ddSqlConnection.Open();
            //ddDR = ddSqlCommand.ExecuteReader(CommandBehavior.CloseConnection);



            //DropDownList1.DataSource = ddDR;
            //DropDownList1.DataTextField = "state_name";
            //DropDownList1.DataValueField = "state_name";

            //DropDownList1.DataBind();
            //ddSqlConnection.Close();

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

        protected void Button1_Click(object sender, EventArgs e)
        {
            //Response.Write(DropDownList1.DataValueField);
        }
        [WebMethod]
        public ArrayList city()
        {
            ArrayList list = new ArrayList();
            String strConnString = ConfigurationManager
                .ConnectionStrings["brokredgeConnectionString"].ConnectionString;
            String strQuery = "select city_id, city_name from city_in_state";
            using (SqlConnection con = new SqlConnection(strConnString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    //cmd.Parameters.AddWithValue("@ContinentID", continentId);
                    cmd.CommandText = strQuery;
                    cmd.Connection = con;
                    con.Open();
                    SqlDataReader sdr = cmd.ExecuteReader();
                    while (sdr.Read())
                    {
                        list.Add(new ListItem(
                       sdr["city_name"].ToString(),
                       sdr["city_id"].ToString()
                        ));
                    }
                    con.Close();
                    return list;
                }
            }
        }
	}
}
